import { defHttp } from '@/utils/http/axios';
import {UploadApiResult} from "@/api/sys/model/uploadModel";
import {AxiosProgressEvent} from "axios";
import {UploadFileParams} from "#/axios";

const prefix = 'template/';
enum Api {
  List = prefix + 'list',
  Create = prefix + 'create', // 保存 新增/修改
  Update = prefix + 'update', // 保存 新增/修改
  Details = prefix + 'details', // 保存 新增/修改
  Delete = prefix + 'delete', // 删除
  DeleteBatch = prefix + 'delete-batch', // 批量删除
  Import = prefix + 'import', // 导入
  Status = prefix + 'status', // 导入
  Export = prefix + 'export', // 导出
  Option = prefix + 'option', // 查询下拉框值
}

/**
 * @description: Get user menu based on id
 */

export const getTemplateListTable = (params: {
  illustrate: string | undefined;
  status: string | number | undefined;
}) => {
  return defHttp.get({ url: Api.List, params });
};

/**
 * @description: 获取详情接口
 * @param {{ id: number }} params ID
 */
export function getTemplateApi(params: { id: number }) {
  return defHttp.get(
    { url: Api.Details, params },
    {
      errorMessageMode: 'message',
    },
  );
}
/**
 * @description: 修改状态
 * @param {{ id: number }} params ID
 */
export function setTemplateStatus(params: { id: number; field: string }) {
  return defHttp.get(
    { url: Api.Status, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 保存接口（新增/修改）
 * @param {any} params 信息
 */
export function createTemplateApi(params: any) {
  return defHttp.post(
    { url: Api.Create, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 保存接口（新增/修改）
 * @param {any} params 信息
 */
export function updateTemplateApi(params: any) {
  return defHttp.post(
    { url: Api.Update, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 删除接口
 * @param {{ id: number }} params ID
 */
export function deleteTemplateApi(params: { id: number }) {
  return defHttp.get(
    { url: Api.Delete, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 批量删除接口
 * @param {{ id: number }} params ID
 */
export function deleteBatchTemplateApi(params: { ids: object }) {
  return defHttp.post(
    { url: Api.DeleteBatch, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 导入接口
 * @param {{ id: number }} params ID
 * @param onUploadProgress
 */
export function importTemplateApi(params: UploadFileParams, onUploadProgress: (progressEvent: AxiosProgressEvent) => void) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: '/test-api/' + Api.Import,
      onUploadProgress,
    },
    params,
  );
}

/**
 * @description: 导出接口
 */
export function exportTemplateApi() {
  return defHttp.get(
    { url: Api.Export },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 获取下拉框值
 */
export function getTemplateOption() {
  return defHttp.get(
    { url: Api.Option },
    {
      errorMessageMode: 'message',
    },
  );
}
